import React, {memo, useEffect,useState} from 'react';
import {shallowEqual, useDispatch, useSelector} from 'react-redux'
import { Table, Tag, Space, Divider, Button, Modal, Spin, message, Select, Form, Input, DatePicker} from 'antd';
import { modifyStudentInfo } from '../../services';
import { NavLink } from 'react-router-dom/cjs/react-router-dom';



//添加空调信息
const { Option } = Select;

export default memo(function ModifyStudentInfo(props) {
    const [form] = Form.useForm(); 
    const [studentInfo, setStudentInfo] = useState(props.location.query)
    // console.log(studentInfo);
    const dispatch = useDispatch()
    //表单布局
    const layout = {
        labelCol: {
          span: 8,
        },
        wrapperCol: {
          span: 16,
        },
      };
      const tailLayout = {
        wrapperCol: {
          offset: 8,
          span: 16,
        },
      };

    

    const onFinish = (values) => {
        // console.log(values);

        modifyStudentInfo(values).then(res => {
            console.log("res",res);
            if(res.status == 200)
            {
                message.success(res.message)
            }else{
                message.error(res.message)
            }

        }).catch(err => {
            message.error(err)
        })
        
      };
      const onWriteChange = (value) => {
        switch(value){
            case '南校区':
                form.setFieldsValue({
                    campus_info: '南'
                });
                break;
            case '北校区':
                form.setFieldsValue({
                    campus_info: '南'
                });
                break;
            default:
                break;
        }
      }

     
    return (
        <div>
            <Divider orientation="left">修改学生信息</Divider>
            <Button type='link'><NavLink to="/admin/room-manage" exact>返回</NavLink></Button>
            <Form
                {...layout}
                form={form}
                name="control-hooks"
                onFinish={onFinish}
                style={{
                    maxWidth: 600,
                }}
                initialValues={{
                    student_number: studentInfo.student_number,
                    student_name: studentInfo.student_name,
                    secondery_college: studentInfo.secondery_college,
                    class_name: studentInfo.class_name,
                    room_number: studentInfo.room_number,
                    phone_number: studentInfo.phone_number,
                    campus_info: studentInfo.campus_info,
                    counsellor_name: studentInfo.counsellor_name,
                    counsellor_number: studentInfo.counsellor_number
                }}
                >
                <Form.Item
                    name="student_number"
                    label="学号"
                    rules={[
                    {
                        required: true,
                        message:"必须填写！"
                    },
                    ]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    name="student_name"
                    label="学生姓名"
                    rules={[
                    {
                        required: true,
                        message:"必须填写！"
                    },
                    ]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    name="secondery_college"
                    label="二级学院"
                    rules={[
                    {
                        required: true,
                        message:"必须填写！"
                    },
                    ]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    name="class_name"
                    label="班级"
                    rules={[
                    {
                        required: true,
                        message:"必须填写！"
                    },
                    ]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    name="room_number"
                    label="寝室号"
                    rules={[
                    {
                        required: true,
                        message:"必须填写！"
                    },
                    ]}
                >
                    <Input placeholder='示例:30#201、 19#5053'/>
                </Form.Item>
                <Form.Item
                    name="phone_number"
                    label="手机号"
                    rules={[
                    {
                        required: true,
                        message:"必须填写！"
                    },
                    ]}
                >
                    <Input />
                </Form.Item>

                <Form.Item
                    name="campus_info"
                    label="所在校区"
                    rules={[
                    {
                        required: true,
                        message:"必须填写！"
                    },
                    ]}
                >
                    <Select
                        onChange={onWriteChange}
                        allowClear
                    >
                        <Option value="南">南校区</Option>
                        <Option value="北">北校区</Option>
                    </Select>
                </Form.Item>
                <Form.Item
                    name="counsellor_name"
                    label="辅导员姓名"
                    rules={[
                    {
                        required: true,
                        message:"必须填写！"
                    },
                    ]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    name="counsellor_number"
                    label="辅导员联系方式"
                    rules={[
                    {
                        required: true,
                        message:"必须填写！"
                    },
                    ]}
                >
                    <Input />
                </Form.Item>
                <Form.Item {...tailLayout}>
                    <Button type="primary" htmlType="submit">
                    提交
                    </Button>
                </Form.Item>
            </Form>

        </div>
    )
})